import request from "@/utils/request";
import {AccountingProjectQuery, AccountingProjectForm} from "./types";
import { AxiosPromise } from "axios";

/**
 * 记账项目分页数据
 *
 * @param queryParams
 */
export function getAccountingProjectPage(
	queryParams: AccountingProjectQuery
): AxiosPromise<PageResult<[]>> {
	return request({
		url: '/api/v1/accountingProject/page',
		method: 'get',
		params: queryParams
	});
}

/**
 * 获取记账项目表单数据
 *
 * @param queryParams
 */
export function getAccountingProjectForm(id: number): AxiosPromise<AccountingProjectForm> {
	return request({
		url: '/api/v1/accountingProject/' + id + '/form',
		method: 'get'
	});
}

/**
 * 保存记账项目
 *
 * @param data
 */
export function saveAccountingProject(data: AccountingProjectForm) {
  return request({
    url: "/api/v1/accountingProject",
    method: "post",
    data: data,
  });
}

/**
 * 删除记账项目
 *
 * @param ids
 */
export function deleteAccountingProject(ids: string) {
	return request({
		url: '/api/v1/accountingProject/' + ids,
		method: 'delete'
	});
}

/**
 * 导出记账项目
 *
 * @param ids
 * @returns
 */
export function exportAccountingProject(ids) {
	return request({
		url: '/api/v1/accountingProject/_export?ids='+ids,
		method: 'get',
		responseType: 'arraybuffer'
	});
}

/**
 * 导入记账项目
 *
 * @param file
 */
export function importAccountProject(file: File) {
	const formData = new FormData();
	formData.append('file', file);
	return request({
		url: '/api/v1/accountingProject/_import',
		method: 'post',
		data: formData,
		headers: {
			'Content-Type': 'multipart/form-data'
		}
	});
}
